home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
boe.pres.k12.wv.us
/
boe.pres.k12.wv.us.zip
/
boe.pres.k12.wv.us
/
Utilities
/
Xerox Workcentre 5335
/
Windows Scan
/
32-bit_x86
/
Francais
/
cpsimage.cab
/
data
/
xps
/
xmetWriteXPS.proc
< prev
next >
Wrap
Text File
|
2009-03-16
|
7KB
|
208 lines
/* What this script for:
Reads in a directory name and gets a list of IMS files from the directory
to package into a XPS file.
The files in the directory are assumed to have FIJI segmentation already
done. Will take the mask layers and assemble a page to do the OCR on.
If no mask layers are present it will use layer 1's contone data to do
the OCR on.
*/
// Load scripted support procedures
#load "sys/stdlib.elf";
#load "xps/xmetWriteImg.proc"; /* XPS support procs */
#load "xps/xmetWriteXML.proc"; /* XPS support procs */
#load "sys/zip.elf"; /* ZIP support objects */
#load "docio/xmldocutils.elf"; /* XIPXML_COALESCEWORDS support */
#import "documentio.ucm"; /* for: XIPXMLtoXPSXML */
#import "builtins.ucm"; /* for: GetDataResource */
/* @WriteXPSOpen
// DESCRIPTION
Deletes an existing file of filename. Creates a temporary directory of
directory of "filename".tmp and sets up the associated sub directories
for the XPS directory structure and write the XPS pages that are not
dependent on image pages.
*/
PROCEDURE
WriteXPSOpen (STRING filename) /* XPS full path name */
{
STRING outdir;
FILE file;
if (filename) {
file = new (FILE, path:filename);
if (file.exists()) {
// SetStatus ( op: "stop", msg: "filename " + filename + " already exists\n");
file.deleteFile();
}
}
outdir = filename + "tmp";
file = new (FILE, path: outdir);
if ( file.isDirectory() ) {
// SetStatus ( op: "stop", msg: "tempdir " + outdir + " already exists\n");
file.deleteFiles();
}
new (FILE, path:outdir).mkdir();
new (FILE, path:outdir + "/_rels").mkdir();
new (FILE, path:outdir + "/Images").mkdir();
new (FILE, path:outdir + "/Fonts").mkdir();
// XML pages not dependent on pages
WriteDocSeq (dir: outdir);
WriteFixedDocHdr (dir: outdir);
}
PROCEDURE
WriteXPSPage( STRING filename, /* XPS full path name */
XIPIMAGE img, /* input image */
INTEGER pgNum, /* page number */
DOUBLE page_x, /* custom page size im mm - default = 0 */
DOUBLE page_y, /* custom page size im mm - default = 0 */
INTEGER unit, /* Resolution unit, 1 = inches, 2 = mm */
INTEGER isTIFF, /* tif or png */
BOOLEAN doCoalesce) /* coalesce ocr'd words in sentences */
{
// Importable value for variable "dir" and "image"
STRING outdir, reldir, thumbName, ocrxml, xipocr;
XIPIMAGE thumb;
INTEGER i, ltype;
outdir = filename + "tmp";
reldir = outdir + "/_rels";
STRING fontpath, myfont, getFontLoc;
FILE file;
for ( i=0; i<img.nlayers; i++ ) {
WriteLayer (img: img,
dir: outdir,
fname: "Layer",
pgNum: pgNum,
layerNum: i,
isTIFF: isTIFF);
}
for ( i=0; i<img.nlayers; i++ )
{
ltype = img.getMember (member:"layerType", num: i);
if (ltype == XIP_Text ) {
DOUBLE fx = 96 / img.resolution[0];
DOUBLE fy = 96 / img.resolution[1];
DOUBLE ww = img.getMember (num:i, member:"width") * fx;
DOUBLE hh = img.getMember (num:i, member:"height") * fy;
XIPIMAGE layer = img.getLayer (num: i);
INTEGER txtfmt = layer.getMember (member: "textformat");
// if ( txtfmt == XIP_XPS_TEXT ) {
// ocrxml = layer.getMember(member:"text");
// continue;
// }
if ( txtfmt != XIP_XML_TEXT ) {
print "Invalid text layer format type to include in XPS";
continue;
}
xipocr = layer.getMember(member:"text");
if (doCoalesce) {
/* May need to override the default tolerences some day */
xipocr = XIPXML_COALESCEWORDS.format( xipxml:xipocr );
}
XIPXMLtoXPSXML(xipxml:xipocr, width:ww, height:hh)
Returns (xpsxml: ocrxml, font: myfont);
fontpath = outdir + "/Fonts/" + myfont;
file = new (FILE, path: fontpath);
if ( myfont && ! file.isFile () ) {
getFontLoc = GetDataResource(filename: "xps/Fonts/"+myfont) ;
System (cmd: "cp \"" + getFontLoc + "\" \"" + fontpath + "\"");
}
} else if (ltype == XIP_Thumbnail) {
thumb = img.getLayer (num: i);
}
}
// Write XML XPS support files
WriteContentTypes ( dir: outdir, page: pgNum);
WriteFixedPg (img: img,
dir: outdir,
page: pgNum,
ocrxml: ocrxml,
page_x: page_x,
page_y: page_y,
unit: unit,
isTIFF: isTIFF);
WriteFixedDoc ( dir: outdir, page: pgNum);
if (thumb) {
thumbName = "/Images/pg" + pgNum + "_thumb.jpg";
// The delete was put in place to avoid changing checksums when units were allowed again
thumb.modheader(_delete:("Origin:units")).writejpgop ( filename: outdir + thumbName);
} else {
thumbName = "";
}
if (pgNum == 1) {
WriteRelsDotRels (dir: reldir, thumbName: thumbName);
}
WriteRelsFixedPg (img: img,
dir: reldir,
page: pgNum,
thumbName: thumbName,
font: myfont,
isTIFF: isTIFF);
Execute ();
}
PROCEDURE
WriteXPSClose (STRING filename,
INTEGER security,
STRING creator,
STRING title,
STRING keyword,
STRING dateTime)
{
FILE outxps = new (FILE, path:filename);
FILE outxpsdir = new (FILE, path:filename + "tmp" );
STRING outdir, reldir;
if (!outxps.getExt() ) {
outxps = new (FILE, parent:outxps.getParentFile(), path:outxps.getName() + ".XPS");
}
outdir = new (FILE, path: filename + "tmp").getAbsolutePath();
reldir = outdir + "/_rels";
WriteFixedDocEnd ( dir: outdir );
WriteMetaData ( dir: outdir,
creator: creator,
title: title,
keyword: keyword,
dateTime: dateTime);
WriteDocSeqRels (dir: reldir);
/* Zip it up! */
ZIP zip = new (ZIP, file:outxps);
zip.setOption( option:ZIP.NODIRS ); // Don't store directory references
// Are we regression testing
if ( dateTime.match ( str: "2007-01-01T" ) )
zip.setOption( option:ZIP.NOTIME ); // Regression testing to remove timestamp
zip.addFiles( dir:outxpsdir, recurse:TRUE );
zip.close();
if (!security) {
outxpsdir.deleteFiles( recurse:TRUE );
}
}